import { createApp } from 'vue'

import App from './App.vue'
import router from './router'
import store from '@/stores'
import * as echarts from 'echarts'

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import '@/assets/css/global.scss' // 全局样式
import '@/assets/css/index.scss' // 样式重置
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

// 引入图标
import 'virtual:svg-icons-register'


// 动态加载配置
const loadRuntimeConfig = async () => {
  const { VITE_APP_ENV } = import.meta.env
  const configPath = VITE_APP_ENV === 'development' ? '/public/config/env.dev.js' : `${import.meta.env.BASE_URL}/config/env.prod.js`
  await import(/* @vite-ignore */ configPath)
}
loadRuntimeConfig()

const app = createApp(App)

// 中文
app.use(ElementPlus, {
  locale: zhCn
})
// element-plus icon
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

app.config.globalProperties.$echarts = echarts
app.use(store)
app.use(router)

app.mount('#app')
